USE Liberty
GO

-- ------------------------------------------------------------------------------------------------
-- Documents Table Create Script
-- ------------------------------------------------------------------------------------------------
SET NOCOUNT OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

PRINT 'Creating Table dbo.Documents...'
GO

IF OBJECT_ID('dbo.Documents', 'U') IS NULL
BEGIN
	CREATE TABLE dbo.Documents
	(OID				bigint		IDENTITY(1, 1)	NOT NULL
	,Version			rowversion
	,GrantID			bigint						NOT NULL
	,TypeOfDocumentID	bigint						NOT NULL

-- ===>>> What are the attributes for a Document?


	,UpdatedDate		datetime					NOT NULL
		CONSTRAINT DFLT_Documents_UpdatedDate DEFAULT GETDATE()
	,CreatedDate		datetime					NOT NULL
		CONSTRAINT DFLT_Documents_CreatedDate DEFAULT GETDATE()

	,CONSTRAINT PK_Documents PRIMARY KEY CLUSTERED( OID ) --ON PRIMARY

	,CONSTRAINT FK_Documents_Grants FOREIGN KEY (GrantID)
		REFERENCES dbo.Grants(OID)

	,CONSTRAINT FK_Documents_TypesOfDocuments FOREIGN KEY (TypeOfDocumentID)
		REFERENCES dbo.TypesOfDocuments(OID)

	)

	PRINT 'Table dbo.Documents has been created successfully.'

END
ELSE 
BEGIN
    PRINT 'Table dbo.Documents already exists.'
END

GO

--DROP TABLE dbo.Documents
